﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using ServisniList.Core;

namespace ServisniList.Rukovatelji
{
    public class ExportServisnogListaUExcelAdapter
    {
        public static void Export(Core.List servisniList, string path)
        {
            using (ExcelPackage package = new ExcelPackage())
            {
                #region Meta data

                package.Workbook.Properties.Author = "Pnp doo";
                package.Workbook.Properties.Title = "Servisni list zaglavlje";

                package.Workbook.Worksheets.Add("Servisni list");
                ExcelWorksheet newSheet = package.Workbook.Worksheets[1];
                newSheet.Name = "Servisni list";

                newSheet.Cells.Style.Font.Size = 11;
                newSheet.Cells.Style.Font.Name = "Calibri";

                #endregion

                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[1, 1], "Servisni list:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[1, 2], servisniList.BrojLista);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[2, 1], "Datum primitka:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[2, 2], servisniList.DatumPrimitka.ToShortDateString());
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[3, 1], "Zaprimljeno u:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[3, 2], servisniList.ZaprimljenoUPnp ? "U PNP" : "Na adresi korisnika");
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[4, 1], "Stranka:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[4, 2], servisniList.Stranka.Naziv);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[5, 1], "Stranka OIB:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[5, 2], servisniList.Stranka.OIB);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[6, 1], "Stranka adresa:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[6, 2], servisniList.Stranka.Adresa);

                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[7, 1], "Stranka telefon:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[7, 2], servisniList.Stranka.BrojTelefona);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[8, 1], "Stranka mobitel:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[8, 2], servisniList.Stranka.BrojMobitela);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[9, 1], "Stranka e-mail:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[9, 2], servisniList.Stranka.Email);
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[10, 1], "Zaprimio:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[10, 2], Rukovatelji.Korisnici.GeneriajPrikazKorisnika(servisniList.Serviser));
                
                ExcelExportHelpers.postaviHeaderCeliju(newSheet.Cells[11, 1], "Opis problema:");
                ExcelExportHelpers.postavipodatakCeliju(newSheet.Cells[11, 2], servisniList.ListOpisProblemaStavkas.FirstOrDefault().OpisProblema.Naziv);

                Byte[] bin = package.GetAsByteArray();
                File.WriteAllBytes(path, bin);
            }
        }
    }
}
